"""
@name : 01.列表
@author : wenyao
@projectname: 空气质量.py
"""
#列表
#1、有序项目集合
#2、里面可以存放任何数据类型
#3、可变数据类型

##列表定义#######################
# >>> lst = []
# >>> type(lst)
# <class 'list'>
# >>> lst2 = list()
# >>> type(lst2)
# <class 'list'>
# >>> lst2 = list("abc")
# >>> lst2
# ['a', 'b', 'c']
# >>> lst3 = list(10)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: 'int' object is not iterable

#[start:end:step]

#下标切片
# >>> lst = ["a",10,1.1,print(),input,None]
#
# >>> lst[2]
# 1.1
# >>> lst[-4]
# 1.1
# >>> lst[10]
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# IndexError: list index out of range
# >>> lst = [1,2,3,4,5]
# >>> lst = [::-1]
#   File "<stdin>", line 1
#     lst = [::-1]
#            ^
# SyntaxError: invalid syntax
# >>> lst[::-1]
# [5, 4, 3, 2, 1]
# >>> lst[2:]
# [3, 4, 5]
# >>> lst[:4]
# [1, 2, 3, 4]
# >>> lst[:4:-1]
# []

############列表的基本操作
#增删改
#增 --append   追加，在列表末尾追加一个元素
# >>> lst.append(6)
# >>> lst2
# [1, 2, 3, 4, '5', 6]
# >>> id(lst)
# 140656578014600
# >>> id(lst2)
# 140656578014600
# >>> lst2 = lst.copy()
# >>> lst2
# [1, 2, 3, 4, '5', 6]
# >>> lst
# [1, 2, 3, 4, '5', 6]
# >>> lst.append(7)
# >>> lst
# [1, 2, 3, 4, '5', 6, 7]
# >>> lst2
# [1, 2, 3, 4, '5', 6]
# >>> id(lst)
# 140656578014600
# >>> id(lst2)
# 140656577526152
# >>> a = 10
# >>> b = a
# >>> id(a)
# 140656602633728
# >>> id(b)
# 140656602633728
# >>> b = 4
# >>> a
# 10


#增加 --- insert
# >>> lst
# [1, 'hello', 'hello', 2, 3, 4, '5', 6, 7, ['a', 'b']]
# >>> lst.insert(2,"world")
# >>> lst
# [1, 'hello', 'world', 'hello', 2, 3, 4, '5', 6, 7, ['a', 'b']]

##增加 -- extend
# >>> lst.extend("abc")
# >>> lst
# [1, 2, 3, 'a', 'b', 'c']
# >>> lst.extend(["x","y"])
# >>> lst
# [1, 2, 3, 'a', 'b', 'c', 'x', 'y']

############删除##########
#pop  默认删除最后一个， 可以指定下标删除
#remove  指定元素删除第一个， 没有这个元素就报错
#del   切片删除
#clear 清空
# >>> lst = ["a","b","a","c","d"]
# >>> lst.pop()
# 'd'
# >>> result = lst.pop()
# >>> result
# 'c'
# >>> lst
# ['a', 'b', 'a']
# >>> result = lst.pop(1)
# >>> result
# 'b'
# >>> lst
# ['a', 'a']
# >>> lst.extend(defag)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# NameError: name 'defag' is not defined
# >>> lst.extend("defag")
# >>> lst
# ['a', 'a', 'd', 'e', 'f', 'a', 'g']
# >>> lst.remove("a")
# >>> lst
# ['a', 'd', 'e', 'f', 'a', 'g']
# >>> lst.remove("h")
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: list.remove(x): x not in list
# >>> lst
# ['a', 'd', 'e', 'f', 'a', 'g']
# >>> id(lst)
# 140265104293256
# >>> del lst[2:4]
# >>> lst
# ['a', 'd', 'a', 'g']
# >>> id(lst)
# 140265104293256
# >>> a = 2
# >>> del a
# >>> a
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# NameError: name 'a' is not defined
# >>> lst.clear()
# >>> lst
# []


#有一条船，30个人在船上，超载了，只能载15个人
#现在决定谁下船，30个进行编号，从1开始数到第9个就下船，最后输出那些人下船了
# a=[]
# init = 1
# while init<=30:
#     a.append(init)
#     init+=1
# i=8
# j=0
# while 1:
#     if len(a)<=15:
#         print("已找出来了！")
#         break
#     print(a.pop(i))
#     i = (i + 8)%len(a)
#     j+=1
# print(f"一共输出了%d"%j)


# member = list(range(1,31))
# print(member)
# while len(member) > 15:
#     i = 1
#     while i < 9:
#         member.append(member.pop(0))
#         i+=1
#     print(member.pop(0))

#列表的修改
# >>> lst = ["a","b","a","c","d"]
# >>> lst[3]="f"
# >>> lst
# ['a', 'b', 'a', 'f', 'd']
# >>> lst[1:2]
# ['b']
# >>> lst[1:2] = "xyz"
# >>> lst
# ['a', 'x', 'y', 'z', 'a', 'f', 'd']
# >>> lst[0]
# 'a'
# >>> lst[0] = "xxyy"
# >>> lst
# ['xxyy', 'x', 'y', 'z', 'a', 'f', 'd']
# >>> lst[1:5]="h"
# >>> lst
# ['xxyy', 'h', 'f', 'd']
# >>> lst[2:2]
# []
# >>> lst[2:2]="uuu"
# >>> lst
# ['xxyy', 'h', 'u', 'u', 'u', 'f', 'd']

###########反转
#reverse  和负切片


#######排序
# >>> lst = ["a","B","z","Z"]
# >>> lst.sort()
# >>> lst
# ['B', 'Z', 'a', 'z']
# >>> lst.sort(reverse=True)
# >>> lst
# ['z', 'a', 'Z', 'B']

#统计类
#>>> lst = ["1","1","a","aa","b","a","c"]
# >>> len(lst)
# 7
# >>> lst.count("a")
# 2
# >>> lst.index("a")
# 2
# >>> lst.index("g")
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: 'g' is not in list

# lst = [3,3,1,5,2,9,4]
# target = 8

# lst = [3,3,1,5,2,9,4]
# target=10
# for i in lst:
#     j = i + 1
#     for j in lst:
#         if (i+j) == target :
#             print(lst.index(i),lst.index(j))
#             break
#     if(i+j) == target:
#         break

# lst=[3,3,1,5,2,9,4]
# target=12
# for i in range(len(lst)-1):
#     f=lst[i]
#     for k in range(i+1,len(lst)):
#         s=lst[k]
#         if f+s==target:
#             break
#     if f+s==target:
#         print("%d-------%d"%(i,k))
#         break
# if f+s!=target:
#     print("none")


# lst=[4,3,1,5,3,9,4]
# target=7
# for index,value in enumerate(lst):
#     if target - value in lst[index+1:]:
#         print(index, lst[index+1:].index(target-value)+index+1)
#         break
